package com.xtayfjpk.security;

import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.Signature;
import java.security.SignedObject;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.RSAKeyGenParameterSpec;

public class SignedObjectTest {

	public static void main(String[] args) throws Exception {
		KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
		AlgorithmParameterSpec algorithmParameterSpec = new RSAKeyGenParameterSpec(1024, new BigInteger("3"));
		generator.initialize(algorithmParameterSpec);
		KeyPair keyPair = generator.generateKeyPair();
		
		byte[] data = "xtayfjpk".getBytes();
		Signature signature = Signature.getInstance("SHA512withRSA");
		SignedObject signedObject = new SignedObject(data, keyPair.getPrivate(), signature);
		System.out.println(signedObject.getSignature());
		
		boolean success = signedObject.verify(keyPair.getPublic(), signature);
		System.out.println(success);
	}

}
